﻿
Partial Class handler
    Inherits System.Web.UI.Page

    '-----------------------------------------------------------
    'The "loadXMLFile" Function accepts two parameters.
    'strXMLFile - The path and file name of the XML file.
    'strXSLFilee - The path and file name of the XSL file.
    '----------------------------------------------------------- 

    Sub loadXMLFile(ByVal strXMLFile As String, ByVal strXSLFile As String)


        'Instantiate the XMLDOM Object that will hold the XML file.
        Dim objXML = Server.CreateObject("Microsoft.XMLDOM")

        'Turn off asyncronous file loading.
        objXML.async = False

        'Load the XML file.
        objXML.load(strXMLFile)


        'Instantiate the XMLDOM Object that will hold the XSL file.
        Dim objXSL = Server.CreateObject("Microsoft.XMLDOM")

        'Turn off asyncronous file loading.
        objXSL.async = False

        'Load the XSL file.
        objXSL.load(strXSLFile)

        'Use the "transformNode" method of the XMLDOM to apply the
        'XSL stylesheet to the XML document. Then the output is
        'written to the client.

        Response.Write(objXML.transformNode(objXSL))

    End Sub


    '-----------------------------------------------------------
    'The "updateXML" Function accepts one parameter.
    'strXMLFile - The path and file name of the XML file.
    '-----------------------------------------------------------
    Sub updateXML(ByVal strXMLFile As String, ByVal strXSLFile As String)

        'Instantiate the XMLDOM Object.
        Dim objDom = Server.CreateObject("Microsoft.XMLDOM")

        'Turn off asyncronous file loading.
        objDom.async = False

        'Load the XML file.
        objDom.load(strXMLFile)

        'objDOM (XMLDOM) object.
        Dim objRoot = objDom.documentElement
        Dim objField As Object

        'Iterate through the Form Collection and write the
        'submitted values to the XML file.
        For x = 1 To Request.Form.Count - 2

            'If it is a button and should be ignored.
            If Request.Form.Keys(x) <> "Submit" Then

                'field_value element (more on this later).
                objField = objRoot.selectSingleNode("field[@id='" & Request.Form.Keys(x) & "']/field_value")

                'element equal to the value of the current form field.
                objField.Text = Request.Form.Item(x)

            End If
        Next


        'After the XML file has been edited, is must be saved.
        objDom.save(strXMLFile)

        'Release all object references.
        objDom = Nothing
        objRoot = Nothing
        objField = Nothing

        'Call the loadXMLFile method, passing in the newly edited
        'XML file and the updatedcontact.xsl style sheet. This will
        'allow the client to see the edited information. More on the
        'updatedcontact.xsl file later.

        loadXMLFile(strXMLFile, strXSLFile)

    End Sub


  


End Class
